package cn.senjoeson.timedowner.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.senjoeson.timedowner.R;
import cn.senjoeson.timedowner.base.SPUtils;

/**
 * Created by senjoeson on 2017/12/23.
 */

public class DisPlayActivity extends Activity {
    @BindView(R.id.createheart)
    ImageView mCreateheart;
    @BindView(R.id.time)
    ImageView mTime;
    @BindView(R.id.agedisc)
    TextView mAgedisc;
    @BindView(R.id.agehead)
    TextView mAgehead;
    @BindView(R.id.year)
    TextView mYear;
    @BindView(R.id.month)
    TextView mMonth;
    @BindView(R.id.week)
    TextView mWeek;
    @BindView(R.id.day)
    TextView mDay;
    @BindView(R.id.hour)
    TextView mHour;
    @BindView(R.id.minute)
    TextView mMinute;
    private String TAG = "DisPlayActivity";

    public String mBirthDate;
    public long mResolveDate;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mBirthDate = SPUtils.getString("birthdate", "");
        Log.d(TAG, mBirthDate);
        mResolveDate = resolveDate();
        int hour = (int) (mResolveDate / 1000 / 3600);
        int mintue = (int) (mResolveDate / 1000 / 60);
        int day = (int) (mResolveDate / 1000 / 3600 / 24);
        int week = (int) (mResolveDate / 1000 / 3600 / 24 / 7);
        int year = (int) (mResolveDate / 1000 / 3600 / 24 / 365);
        int month = year * 12;


        mAgedisc.setText("你已经" + String.valueOf(mResolveDate / 1000 / 3600 / 365 / 24) + "岁了");
        mYear.setText("" + year + "\n" + "年");
        mMonth.setText("" + month + "\n" + "月");
        mDay.setText("" + day + "\n" + "日");
        mWeek.setText("" + week + "\n" + "周");
        mHour.setText("" + hour + "\n" + "小时");
        mMinute.setText("" + mintue + "\n" + "分钟");

        mCreateheart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(DisPlayActivity.this,ShowCreateHeartActivity.class));
            }
        });


    }


    private long resolveDate() {
        long result = 0;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);
        Date birthdate = null;
        try {
            birthdate = simpleDateFormat.parse(mBirthDate);
            // Log.d(TAG, date1.toString());
            long birthdateTime = birthdate.getTime();
            Date date = new Date();
            long currentTime = date.getTime();
            result = currentTime - birthdateTime;
            Log.d("time:", "" + result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
}
